import com.unipay.spring.aop.annotation.Calculator;
import com.unipay.spring.aop.annotation.CalculatorImpl;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @BelongsProject: SSM
 * @Author: cmy
 * @CreateTime: 2023-01-17  14:05
 * @Description: TODO
 */

public class AopAnnotataion {

    @Test
    public void aopAnnotation(){
        ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("aop-annotation.xml");
/*
        TODO 使用了AOP之后，在IOC容器中不能直接访问“目标类”；
            只能通过代理对象、代理类，虽然不知道代理对象是谁，但一定和目标对象实现类“相同的接口”
        CalculatorImpl bean = ioc.getBean(CalculatorImpl.class);
        bean.add(1, 2);
        org.springframework.beans.factory.NoSuchBeanDefinitionException:
            No qualifying bean of type 'com.unipay.spring.aop.annotation.CalculatorImpl' available
*/

        Calculator calculator = ioc.getBean(Calculator.class);
        int add = calculator.add(2, 5);
        System.out.println(add);
        System.out.println(calculator.sub(4, 10));

//        System.out.println(calculator.div(4, 0));
    }
}
